var $btn =$("#btn");
$btn.click(function(){
	var chk_value =""; 
	$('input[name="allparts"]:checked').each(function(i,msg){ 
	chk_value+=$(this).val()+","; 
	});
	$.ajax({
        type: "post",
        url: "manager_powerpart_update",
        data: {part_id:$("#partId").val(),power_id:chk_value},
        success: function(data){
        	if(data=='success'){
        	alert('success!');
        	window.location.href="/manager_power_part_list?partId="+$("#partId").val();
        	}else{
        	alert('failure!');	
        	}
        }
    });
});

$(function() { 
	$.ajax({
        type: "post",
        url: "manager_part_power_list",
        data: {partId:$("#partId").val()},
        dataType: "json",
        success: function(data){
     	   $.each(eval(data), function(i,msg){
      		 for(var j=0;j<msg.length;j++){
      			 var $parts = $('input[name="allparts"]');
        		 $parts.each(function() {
        			 if ($(this).attr('value')==msg[j].power_id) {
        				 $(this).attr('checked','true');
            			}
        		   });
      		 }
      		
           });
        }
    });
	
	});